# -*- encoding: utf-8 -*-
"""
@version: 1.0
@author: yang ming
@contact: 122162005@qq.com
@site: http://www.idianjia.com/
@software: PyCharm
@file: sock.py
@time: 2016/3/23 10:13
"""

from socket import *

HOST = ''
PORT = 60000
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(20)


def ser():
    while True:
        tcpCliSock, addr = tcpSerSock.accept()
        print(addr)

        while True:
            data = tcpCliSock.recv(BUFSIZ).decode("utf-8")
            print(data)
            if not data:
                break
            # elif "timeout":
            #     break

            tcpCliSock.send("or other message".encode("utf-8"))
        tcpCliSock.close()

    tcpSerSock.close()


class TcpSerSock(object):
    pass


if __name__ == "__main__":
    ser()
